<?php
App::uses('BaseAuthenticate', 'Controller/Component/Auth');

class MobileAuthenticate extends BaseAuthenticate {

    public function authenticate(CakeRequest $request, CakeResponse $response) {
        if ($request->is('mobile') && (isset($request->data['hash_session']) || isset($request->query['hash_session']))) {
        	App::uses('Conductor', 'Model');
        	if ($request->is('get')) {
        		return Conductor::isLoggedIn($request->query['hash_session']);
        	}
        	else if ($request->is('post')) {
        		return Conductor::isLoggedIn($request->data['hash_session']);
        	}
        }
        return FALSE;
    }

    public function getUser(CakeRequest $request) {
        App::uses('Conductor', 'Model');
        $conductor = new Conductor();
        if ($request->is('get')) {
            if (isset($request->query['hash_session'])) {
                return $conductor->isLoggedIn($request->query['hash_session']);
            }
        }
        else if ($request->is('post')) {
            if (isset($request->data['hash_session'])) {
                return $conductor->isLoggedIn($request->data['hash_session']);
            }
        }
        return FALSE;
    }

    public function logout($user) {
        App::uses('Conductor', 'Model');
        $conductor = new Conductor();
        $conductor->logout($user['Conductor']['hash_sesion_conductor']);
    }
}